﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using JESAI.Application.Abstractions.Admin;
using JESAI.Application.Abstractions.Admin.Dtos.Platform;
using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Service.Admin;
using JESAI.Framework.Filters;
using JESAI.Platform.Domain.Admin.Entities;
using SqlSugar;
using System;

namespace Bucket.Admin.Web.Controllers
{
    /// <summary>
    /// 平台管理
    /// </summary>
    [ApiController]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class PlatformController : ControllerBase
    {
        private readonly IPlatformService _platformService;
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="sqlSugarDbContextFactory"></param>
        /// <param name="mapper"></param>
        public PlatformController(IPlatformService platformService)
        {
            _platformService = platformService;
        }

        /// <summary>
        /// 查询平台列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("/Platform/QueryPlatforms")]
        public BaseOutput<object> QueryPlatforms()
        {
            var list = _platformService.QueryPlatforms();
            return new BaseOutput<object> { Data = list };
        }
        /// <summary>
        /// 设置平台信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/Platform/SetPlatform")]
        public BaseOutput SetPlatform([FromBody] SetPlatformInput input)
        {
            _platformService.UpdateOrInsert(input);

            return new BaseOutput { };
        }

        [HttpGet("/Platform/DeletePlatforms")]
        public BaseOutput DeletePlatforms(long[] ids)
        {
            _platformService.DeletePlatforms(ids);
            return new BaseOutput { };
        }

        [HttpGet("/Platform/DeletePlatform")]
        public BaseOutput DeletePlatform(long id)
        {
            _platformService.DeletePlatform(id);
            return new BaseOutput { };
        }
    }
}